package Service;

import java.util.ArrayList;
import java.util.List;

import dao.BookDao;
import dao.ProjectDao;
import pojo.Book;
import pojo.PageBean;
import pojo.Project;

public class BookService {
	BookDao cdao;
	public PageBean<Book> show(int currentPage,int pageSize) {
		cdao = new BookDao();
		PageBean<Book> pb = new PageBean<Book>();
		pb.setList(cdao.PageData(currentPage, pageSize));
		pb.setTotal(cdao.getTotal());
		int totalPage=(cdao.getTotal()%pageSize==0)?(cdao.getTotal()/pageSize):(cdao.getTotal()/pageSize+1);
		pb.setTotalPage(totalPage);
		pb.setCurrentPage(currentPage);
		pb.setPageSize(pageSize);
		return pb;
	}
	public List<Book> showBookByType(int currentPage,int pageSize,int id){
		cdao = new BookDao();
		List<Book>list=new ArrayList<Book>();
		list=cdao.showBookByType(currentPage, pageSize, id);
		return list;
	}
	public int add(Book p) {
		cdao=new BookDao();
		int flag=cdao.add(p);
		return flag;
	}
	public int update(Book p) {
		cdao=new BookDao();
		int flag=cdao.update(p);
		return flag;
	}
	public Book getBook(int id) {
		cdao=new BookDao();
		Book p =cdao.getOneBook(id);
		return p;
	}
	public int delBook(int id) {
		int flag=0;
		cdao=new BookDao();
		flag=cdao.del(id);
		return flag;
	}
}